package team.southcat.wsyygh.hospital.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.hospital.service.DepartmentService;
import team.southcat.wsyygh.hospital.service.HospitalService;
import team.southcat.wsyygh.hospital.service.ScheduleService;
import team.southcat.wsyygh.model.pojo.hospital.*;
import team.southcat.wsyygh.model.pojo.order.ScheduleOrderVo;

import java.util.List;

@Api(tags = "前台医院接口")
@RestController
@RequestMapping("/api/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("医院列表分页查询")
    @GetMapping("/getAllHospitalPage/{page}/{limit}")
    public Result getAllHospitalPage(@PathVariable int page, @PathVariable int limit, HospitalVo hospitalVo){
        Page hospitalPageList = hospitalService.getHospitalPageList(page, limit, hospitalVo);
        return hospitalPageList != null ? Result.ok(hospitalPageList) : Result.fail();
    }

    @ApiOperation("根据id获取医院信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable int id){
        Hospital hospital = hospitalService.getById(id);
        return Result.ok(hospitalService.switchVo(hospital));
    }

    @ApiOperation("根据医院id获取所有科室")
    @GetMapping("/getDepartmentById/{id}")
    public Result getDepartmentById(@PathVariable int id){
        List<DepartmentVo> departmentList = departmentService.getByHospitalId(id);
        return departmentList != null ? Result.ok(departmentList) : Result.fail().message("不存在科室信息");
    }

    @ApiOperation("根据名称获取")
    @GetMapping("/getByHospitalName/{hosname}")
    public Result getByHospitalName(@PathVariable String hosname){
        List<Hospital> hospitals = hospitalService.getByHospitalName(hosname);
        return Result.ok(hospitals);
    }

    //根据排班id获取预约下单数据
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

}
